class Solution3 {
    public static String removeDuplicates(String s) {
        StringBuffer ret = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            if (ret.length() > 0 && ret.charAt(ret.length() - 1) == s.charAt(i)) {
                ret.deleteCharAt(ret.length() - 1);
            }else {
                ret.append(s.charAt(i));
            }
        }
        return ret.toString();
    }

    public static void main(String[] args) {
        System.out.println(Solution3.removeDuplicates("abbaca"));
    }
}